package com.hntech.base.io.bio;

import com.hntech.util.IOUtil;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.Scanner;

/**
 * @Autho changqi.wu
 * @Date 路在脚下，使劲踩！
 */
public class BioClient {

    private static final int client_port = 12541;

    public static void main(String[] args) throws IOException {


        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            Socket socket = new Socket(BioServer.address, BioServer.port);
            String line = scanner.next();
            OutputStream outputStream = socket.getOutputStream();
//            outputStream.write(IOUtil.stringToByte(line));
//            outputStream.flush();

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream));
            //向服务器端发送一条消息
            bw.write(line);
            bw.flush();

            InputStream inputStream = socket.getInputStream();
            System.out.println("response:" + IOUtil.readInputStream(inputStream));
            socket.close();
        }

    }

}
